<template>
	<div class="app-container">
		<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
			label-width="68px">
			<el-form-item label="运单号" prop="number">
				<el-input v-model="queryParams.number" placeholder="请输入运单号" clearable
					@keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="订单时间">
				<el-date-picker v-model="daterangeOrderTime" style="width: 240px" value-format="yyyy-MM-dd"
					type="daterange" range-separator="-" start-placeholder="开始日期"
					end-placeholder="结束日期"></el-date-picker>
			</el-form-item>
			<el-form-item label="装车时间">
				<el-date-picker v-model="daterangeLoadingTime" style="width: 240px" value-format="yyyy-MM-dd"
					type="daterange" range-separator="-" start-placeholder="开始日期"
					end-placeholder="结束日期"></el-date-picker>
			</el-form-item>
			<el-form-item label="卸车时间">
				<el-date-picker v-model="daterangeUnloadTime" style="width: 240px" value-format="yyyy-MM-dd"
					type="daterange" range-separator="-" start-placeholder="开始日期"
					end-placeholder="结束日期"></el-date-picker>
			</el-form-item>
			<el-form-item label="支付方式" prop="payMethod">
				<el-select v-model="queryParams.payMethod" placeholder="请选择支付方式" clearable>
					<el-option v-for="dict in dict.type.payment_category" :key="dict.value" :label="dict.label"
						:value="dict.value" />
				</el-select>
			</el-form-item>
			<el-form-item label="订单状态" prop="status">
				<el-select v-model="queryParams.status" placeholder="请选择订单状态" clearable>
					<el-option v-for="dict in dict.type.cargo_user_orders" :key="dict.value" :label="dict.label"
						:value="dict.value" />
				</el-select>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
				<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
			</el-form-item>
		</el-form>

		<el-row :gutter="10" class="mb8">
			<!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['client:orders:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['client:orders:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['client:orders:remove']"
        >删除</el-button>
      </el-col> -->
			<el-col :span="1.5">
				<el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
					v-hasPermi="['client:orders:export']">导出</el-button>
			</el-col>
			<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
		</el-row>

		<el-table v-loading="loading" :data="ordersList" @selection-change="handleSelectionChange">
			<el-table-column type="selection" width="55" align="center" />
			<el-table-column label="ID" align="center" prop="id" />
			<el-table-column label="运单号" align="center" prop="number" />
			<el-table-column label="订单生成时间" align="center" prop="orderTime" width="180">
				<template slot-scope="scope">
					<span>{{ parseTime(scope.row.orderTime, '{y}-{m}-{d}') }}</span>
				</template>
			</el-table-column>
			<el-table-column label="运费" align="center" prop="price" />
			<el-table-column label="装车时间" align="center" prop="loadingTime" width="180">
				<template slot-scope="scope">
					<span>{{ parseTime(scope.row.loadingTime, '{y}-{m}-{d}') }}</span>
				</template>
			</el-table-column>
			<el-table-column label="卸车时间" align="center" prop="unloadTime" width="180">
				<template slot-scope="scope">
					<span>{{ parseTime(scope.row.unloadTime, '{y}-{m}-{d}') }}</span>
				</template>
			</el-table-column>
			<el-table-column label="支付方式" align="center" prop="payMethod">
				<template slot-scope="scope">
					<dict-tag :options="dict.type.payment_category" :value="scope.row.payMethod" />
				</template>
			</el-table-column>
			<el-table-column label="收款账户" align="center" prop="collectionAccountId" />
			<el-table-column label="付款时间" align="center" prop="paymentTime" width="180">
				<template slot-scope="scope">
					<span>{{ parseTime(scope.row.paymentTime, '{y}-{m}-{d}') }}</span>
				</template>
			</el-table-column>
			<el-table-column label="货源信息" align="center" prop="cargoGoods.name" />
			<el-table-column label="车辆信息" align="center" prop="carowner.carOwner" />
			<el-table-column label="订单状态" align="center" prop="status">
				<template slot-scope="scope">
					<dict-tag :options="dict.type.cargo_user_orders" :value="scope.row.status" />
				</template>
			</el-table-column>
			<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
				<template slot-scope="scope">
					<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
						v-hasPermi="['client:orders:remove']">删除</el-button>
				</template>
			</el-table-column>
		</el-table>

		<pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
			@pagination="getList" />
	</div>
</template>

<script>
	import {
		listOrders,
		getOrders,
		delOrders,
		addOrders,
		updateOrders
	} from "@/api/client/orders";
	import {
		listGoodsAll
	} from "@/api/employer/goods";
	import {
		listCardetialsAll
	} from "@/api/driver/cardetials";

	export default {
		name: "Orders",
		dicts: ['cargo_user_orders'],
		data() {
			return {
				// 遮罩层
				loading: true,
				// 选中数组
				ids: [],
				// 非单个禁用
				single: true,
				// 非多个禁用
				multiple: true,
				// 显示搜索条件
				showSearch: true,
				// 总条数
				total: 0,
				// 货主订单表格数据
				ordersList: [],
				// 弹出层标题
				title: "",
				// 是否显示弹出层
				open: false,
				// 订单状态时间范围
				daterangeOrderTime: [],
				// 订单状态时间范围
				daterangeLoadingTime: [],
				// 查询参数
				queryParams: {
					pageNum: 1,
					pageSize: 10,
					number: null,
					orderTime: null,
					loadingTime: null,
					unloadTime: null,
					payMethod: null,
					status: 0
				},
				// 表单参数
				form: {},
				// 表单校验
				rules: {
					number: [{
						required: true,
						message: "运单号不能为空",
						trigger: "blur"
					}],
					orderTime: [{
						required: true,
						message: "订单生成时间不能为空",
						trigger: "blur"
					}],
					price: [{
						required: true,
						message: "运费不能为空",
						trigger: "blur"
					}],
					loadingTime: [{
						required: true,
						message: "装车时间不能为空",
						trigger: "blur"
					}],
				}
			};
		},
		created() {
			this.getList();
		},
		methods: {
			/** 查询货主订单列表 */
			getList() {
				this.loading = true;
				this.queryParams.params = {};
				if (null != this.daterangeOrderTime && '' != this.daterangeOrderTime) {
					this.queryParams.params["beginOrderTime"] = this.daterangeOrderTime[0];
					this.queryParams.params["endOrderTime"] = this.daterangeOrderTime[1];
				}
				if (null != this.daterangeLoadingTime && '' != this.daterangeLoadingTime) {
					this.queryParams.params["beginLoadingTime"] = this.daterangeLoadingTime[0];
					this.queryParams.params["endLoadingTime"] = this.daterangeLoadingTime[1];
				}
				if (null != this.daterangeUnloadTime && '' != this.daterangeUnloadTime) {
					this.queryParams.params["beginUnloadTime"] = this.daterangeUnloadTime[0];
					this.queryParams.params["endUnloadTime"] = this.daterangeUnloadTime[1];
			    }
				listOrders(this.queryParams).then(response => {
					this.ordersList = response.rows;
					this.total = response.total;
					this.loading = false;
				});
			},

			/** 搜索按钮操作 */
			handleQuery() {
				this.queryParams.pageNum = 1;
				this.getList();
			},
			/** 重置按钮操作 */
			resetQuery() {
				this.daterangeOrderTime = [];
				this.daterangeLoadingTime = [];
				this.daterangeUnloadTime = [];
				this.resetForm("queryForm");
				this.handleQuery();
			},
			// 多选框选中数据
			handleSelectionChange(selection) {
				this.ids = selection.map(item => item.id)
				this.single = selection.length !== 1
				this.multiple = !selection.length
			},

			/** 删除按钮操作 */
			handleDelete(row) {
				const ids = row.id || this.ids;
				this.$modal.confirm('是否确认删除货主订单编号为"' + ids + '"的数据项？').then(function() {
					return delOrders(ids);
				}).then(() => {
					this.getList();
					this.$modal.msgSuccess("删除成功");
				}).catch(() => {});
			},

			/** 导出按钮操作 */
			handleExport() {
				this.download('client/orders/export', {
					...this.queryParams
				}, `orders_${new Date().getTime()}.xlsx`)
			}
		}
	};
</script>